﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using DAL;

namespace BUS
{
    public class LOAI_SAN_PHAMBUS
    {
        public static void insert(LOAI_SANPHAM lsp)//thêm sản phẩm
        {
            LOAI_SAN_PHAMDAL lspdal = new LOAI_SAN_PHAMDAL();
            lspdal.Insert(lsp);
        }

        public static void update(LOAI_SANPHAM lsp)
        {
            LOAI_SAN_PHAMDAL lspdal = new LOAI_SAN_PHAMDAL();
            lspdal.Update(lsp);
        }

        public static void update_status(LOAI_SANPHAM lsp)
        {

            LOAI_SAN_PHAMDAL lspdal = new LOAI_SAN_PHAMDAL();
            lspdal.Update_status(lsp);
        }

        public static void Delete(int id)
        {

            LOAI_SAN_PHAMDAL loaispdal = new LOAI_SAN_PHAMDAL();
            loaispdal.Delete(id);
        }
        public static int CheckExist(int id)
        {
            int t = 0;
            LOAI_SAN_PHAMDAL loaisp = new LOAI_SAN_PHAMDAL();
            
            
            
            loaisp.Get("Where MA_LOAI_CHA = " + id.ToString(), 0, 0, Loaispcolum.MA_LOAI.ToString(), "ASC",out t);
            return t;
        }
        public static Loaisanphamcollection  GET(string Where, int PageIndex, int PageSize,
                                       string OrderBy, string OrderDirection,
                                       out int TotalRecords)
        {

            LOAI_SAN_PHAMDAL loaispdal = new LOAI_SAN_PHAMDAL();
            return loaispdal.Get(Where, PageIndex, PageSize,
                            OrderBy, OrderDirection, out TotalRecords);
        }

        public static Loaisanphamcollection GetAll()
        {
            int t = 0;
            LOAI_SAN_PHAMDAL loaispdal = new LOAI_SAN_PHAMDAL();
            return loaispdal.Get("where 1=1", 0, 1000,
                Loaispcolum.MA_LOAI.ToString(), "DESC", out t);

        }
        public static LOAI_SANPHAM GetByID(int iD)
        {
            int t = 0;
            LOAI_SAN_PHAMDAL sanphamdal = new LOAI_SAN_PHAMDAL();
            Loaisanphamcollection SANPHAMcollection = sanphamdal.Get("where " + Loaispcolum.MA_LOAI.ToString() + " = " + iD.ToString(), 0, 0,
                Loaispcolum.TEN_LOAI.ToString(), "ASC", out t);
            if (SANPHAMcollection.Count == 1)
                return SANPHAMcollection[0];
            return null;
        }
        public static string GetCha(int maloaicha)
        {
            int t = 0;
            LOAI_SAN_PHAMDAL sanphamdal = new LOAI_SAN_PHAMDAL();
            Loaisanphamcollection SANPHAMcollection = sanphamdal.Get("where " + Loaispcolum.MA_LOAI.ToString() + " = " + maloaicha.ToString(), 0, 0,
                Loaispcolum.MA_LOAI.ToString(), "ASC", out t);
            if (SANPHAMcollection.Count == 1)
                return SANPHAMcollection[0].Tenloaisp;
            return null;
        }
    }
}
